package com.xuecheng.manage_cms.controller;


import com.xuecheng.api.cms.CmsPageControllerApi;
import com.xuecheng.framework.domain.cms.CmsPage;
import com.xuecheng.framework.domain.cms.request.QueryPageRequest;
import com.xuecheng.framework.domain.cms.response.CmsPageResult;
import com.xuecheng.framework.domain.cms.response.CmsPostPageResult;
import com.xuecheng.framework.model.response.QueryResponseResult;
import com.xuecheng.framework.model.response.ResponseResult;
import com.xuecheng.manage_cms.service.PageService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * @author zhaoxiang
 * @version 1.0
 * @Date 2019/8/24 15:12
 */
@RestController
@RequestMapping("/cms/page")
public class CmsPageController implements CmsPageControllerApi {

    @Autowired
    private PageService pageService;

    @Override
    @ApiOperation("分页查询页面列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "页码", required = true,paramType = "path",dataType = "int"),
            @ApiImplicitParam(name = "size", value = "每页记录", required = true,paramType = "path",dataType = "int"),

    })

    @GetMapping("/list/{page}/{size}")
    public QueryResponseResult findList(@PathVariable("page") int page, @PathVariable("size") int size, QueryPageRequest queryPageRequest) {
        return pageService.findList(page, size, queryPageRequest);
    }

    @Override
    @PostMapping("/add")
    @ApiOperation("新增页面")
    public CmsPageResult add(@RequestBody CmsPage cmsPage) {
        return pageService.add(cmsPage);
    }

    @Override
    @GetMapping("/get/{id}")
    @ApiOperation("根据pageId查询页面信息")
    public CmsPage findByPageId(@PathVariable("id") String pageId) {
        return pageService.findByPageId(pageId);
    }

    @Override
    @PutMapping("/edit/{pageId}")
    @ApiOperation("修改页面")
    public CmsPageResult edit(@PathVariable("pageId") String pageId, @RequestBody CmsPage cmsPage) {
        return pageService.update(pageId,cmsPage);
    }

    @Override
    @DeleteMapping("/del/{pageId}")
    @ApiOperation("删除页面")
    public ResponseResult delete(@PathVariable("pageId") String pageId) {
        return pageService.delete(pageId);
    }

    @Override
    @GetMapping("/selectSiteList")
    @ApiOperation("站点下拉菜单列表")
    public QueryResponseResult findSiteList(){
        return pageService.findSiteList();
    }

    @Override
    @GetMapping("/selectTemplateList")
    @ApiOperation("模板下拉菜单列表")
    public QueryResponseResult findTemplateList() {
        return pageService.findTemplateList();
    }

    @Override
    @PostMapping("/postPage/{pageId}")
    @ApiOperation("页面发布")
    public ResponseResult post(@PathVariable("pageId") String pageId) {
        return pageService.postPage(pageId);
    }

    @Override
    @PostMapping("/save")
    public CmsPageResult save(@RequestBody CmsPage cmsPage) {
        return pageService.save(cmsPage);
    }

    @Override
    @ApiOperation("一键发布页面")
    @PostMapping("/postPageQuick")
    public CmsPostPageResult postPageQuick(@RequestBody CmsPage cmsPage) {
        return pageService.postPageQuick(cmsPage);
    }
}


